package com.wuyou.mid;

import javax.jnlp.IntegrationService;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * 698. 划分为k个相等的子集
 */
public class CanPartitionKSubsets {


    public boolean solution_1(int[] nums, int k) {
        int sum = 0;
        for (int num : nums) {
            sum += num;
        }
        if (sum % nums.length != 0) return false;
                int left = 0;
        int right = nums.length - 1;

        Arrays.sort(nums);
        int length = nums.length / k;
        int remain = nums.length % k;
        if (remain > 0) {
            if (remain == 1 && nums[nums.length - 1] == sum / nums.length) {
                right = nums.length - 2;
            } else {
                List<Integer> remainList = new ArrayList<>();
                int tempSum = 0;
                for (int i = 0; i < nums.length; i++) {


                    if (remainList.size() == remain) {
                        break;
                    }

                }
            }
        }
        while (left != right) {

            int leftTemp = nums[left];
            int rightTemp = nums[right];

            if ((nums.length - 1) % leftTemp == 0 && nums.length / leftTemp == k) {
                return true;
            }
            if (nums.length % rightTemp == 0 && nums.length / rightTemp == k) {
                return true;
            }
            left++;
            right--;
        }
        return false;
    }
}
